#include "CustomerInfoDialog.h"

CustomerInfoDialog::CustomerInfoDialog(CustomerInfo &info, const QString& defaultCustomerName, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::CustomerInfoDialog),
    info_(info)
{
    ui->setupUi(this);

    ui->longtitudeEdit->setText(QString::number(info.coordinate.x()));
    ui->latitudeEdit->setText(QString::number(info.coordinate.y()));
    ui->customerNameEdit->setText(defaultCustomerName);

    QObject::connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(acceptInfo()));
}

CustomerInfoDialog::~CustomerInfoDialog()
{
    delete ui;
}

void CustomerInfoDialog::acceptInfo()
{
    info_.name = ui->customerNameEdit->text();
    info_.demand = ui->demandSpinBox->value();
    if(ui->typeComboBox->currentIndex() == 0)
        info_.isBackhaul = false;
    else
        info_.isBackhaul = true;
}

/// /////////////////////////

CustomerPtrDialog::CustomerPtrDialog(CustomerPtr customer, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::CustomerInfoDialog),
    customer_(customer)
{
    ui->setupUi(this);

    ui->label->setText("Edit customer information");

    ui->longtitudeEdit->setText(QString::number(customer->getCoordinate()->longitude()));
    ui->latitudeEdit->setText(QString::number(customer->getCoordinate()->latitude()));
    ui->customerNameEdit->setText(customer->getName());
    if(customer->getType())
        ui->typeComboBox->setCurrentIndex(1);

    QObject::connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(acceptInfo()));
}

CustomerPtrDialog::~CustomerPtrDialog()
{
    delete ui;
}

void CustomerPtrDialog::acceptInfo()
{

}
